package com.zany.net.service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zany.net.dto.InterfaceSerializer;
import com.zany.net.dto.request.QueryMoneyReq;
import com.zany.net.dto.request.RequestBody;
import com.zany.net.dto.request.RequestEntity;

public abstract class AbsConvertJson {
    abstract Class getReqEntity();

    abstract void setupEntity(RequestEntity requestEntity);

    void convertRequestEntity(String jsonStr) {
        Class clazz = getReqEntity();
        InterfaceSerializer interfaceSerializer = InterfaceSerializer.interfaceSerializer(clazz);
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(RequestBody.class, interfaceSerializer)
                .create();
        RequestEntity entity = gson.fromJson(jsonStr, RequestEntity.class);
        setupEntity(entity);
    }
}
